package com.sikadwafastdaisfondturbo.pretloan.adapter

import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import com.sikadwafastdaisfondturbo.lib_baseadapter.SikadwaRecyclerViewAdapter
import com.sikadwafastdaisfondturbo.lib_baseadapter.SikadwaViewHolderHelper
import com.sikadwafastdaisfondturbo.pretloan.R
import com.sikadwafastdaisfondturbo.pretloan.databinding.ItemPermissionReasonChildBinding
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/4/23 17:24
 * @Annotation：权限声明适配器
 */
class PermissionReasonAdapter(recyclerView: RecyclerView?) : SikadwaRecyclerViewAdapter<JSONObject>(recyclerView,R.layout.item_permission_reason) {

    override fun setItemChildListener(helper: SikadwaViewHolderHelper, viewType: Int) {
    }

    override fun fillData(helper: SikadwaViewHolderHelper, position: Int, model: JSONObject) {
        val imgIcon = helper.getImageView(R.id.imgIcon)
        imgIcon.setImageResource(model.optInt("icon"))
        val textReasonTitle = helper.getTextView(R.id.textReasonTitle)
        textReasonTitle.text = model.optString("title")

//        helper.setText(R.id.textAgreeAmount," +${model.optString("loanAmount")}")
//        helper.setText(R.id.textPassRate," +${model.optString("passRate")}"+"%")

        val permissionDesLayout = helper.getView<LinearLayout>(R.id.permissionDesLayout)
        permissionDesLayout.removeAllViews()

        val itemList = model.optJSONArray("msgList")
        itemList?.let {
            for (i in 0..< itemList.length()){
                val item = itemList.optJSONObject(i)
                val itemView = ItemPermissionReasonChildBinding.inflate(LayoutInflater.from(mContext))
                val showTitle = item.optString("title")
                if (showTitle.isNotEmpty()){
                    itemView.tvTitle.text = showTitle
                    itemView.tvTitle.visibility = View.VISIBLE
                } else {
                    itemView.tvTitle.visibility = View.GONE
                }
                itemView.tvDes.text = item.optString("des")
                permissionDesLayout.addView(itemView.root)
            }
        }

    }
}